<template>
  <!-- 会员概览 -->
  <div class="members-container">
    <div class="my-profit flex-center column">
      <img src="@/assets/icons/coin-dollar.svg" alt="" class="coin-dollar">
      <div class="title">My Profit</div>
    </div>

    <div class="profit-details">
      <router-link tag="div" to="/Sub/Profits" class="profit-item elevation-2">
        <img src="@/assets/icons/bag-dollar.svg" alt="" class="icon">
        <span class="title">My</span>
        <span class="numbers">$ {{ profit.my || 0 }}</span>
      </router-link>
      <router-link tag="div" to="/Sub/MembersList" class="profit-item elevation-2">
        <img src="@/assets/icons/group.svg" alt="" class="icon">
        <span class="title">Members</span>
        <span class="numbers">{{ profit.members }}</span>
      </router-link>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Api } from '@/api';
declare const $Vue: Vue;

@Component({
  components: {
  },
})
export default class Members extends Vue {

  private profit = {
    my: 0,
    members: 0,
  }

  private tableData: any = [];

  protected mounted() {
    $Vue.$emit('title', {
      message: 'Members',
    });

    this.getProfitMembers();
    this.getProfitAmount();
  }

  private async getProfitAmount() {
    const params: any = {
    };
    const { data } = await Api.getProfitAmount.r(params);
    console.log("getProfitAmount", data);
    if (data.result === 0) {
      this.profit.my = data.data;
    } else {
      this.$createToast({
        txt: "Something has gone wrong.",
        type: "warn",
        time: 3000
      }).show();
    }
  }

  private async getProfitMembers() {
    const params: any = {
    };
    const { data } = await Api.getProfitMembers.r(params);
    console.log("getProfitMembers", data);
    if (data.result === 0) {
      this.profit.members = data.data.length;
      this.tableData = data.data;
    } else {
      this.$createToast({
        txt: "Something has gone wrong.",
        type: "warn",
        time: 3000,
      }).show();
    }
  }
}
</script>

<style lang="less" scoped>
.members-container {
    width: 100%;
  height: 100%; 
  .my-profit {
    height: 10rem;
    border-bottom: 1px solid #cdcdcd;
    .coin-dollar {
      width: 4rem;
      height: 4rem;
    }
    .title {
      font-size: 1.4rem;
      color: #666;
      margin-top: 1rem;
      font-weight: bold;
    }
  }
  .profit-details {
    display: flex;
    justify-content: space-around;
    padding-top: 4rem;
    .profit-item {
      width: 7rem;
      height: 9rem;
      flex-direction: column;
    justify-content: space-around;
    display: flex;
    align-items: center;
        background: antiquewhite;
    border-radius: 8px;
      .icon {
        width: 3rem;
        height: 3rem;
      }
      .title {
        font-size: 1.2rem;
        color: #888;
      }
      .numbers {
        color: #444;
        font-size: 1.3rem;
      }
    }
  }
}
</style>
